package cn.tedu.seckill.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendController {
    /*
    请求地址:/send
    请求方式:get
    请求参数:String msg
    返回结果: success
     */
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RequestMapping("/send")
    public String send(String msg){
        //一组api方法都可以发送消息
        rabbitTemplate
                .convertAndSend(
                        "direct_EX",
                        "上海",
                        msg);//自动的properties
        MessageProperties properties=new MessageProperties();
        properties.setPriority(100);
        Message message=new Message(msg.getBytes(),properties);
        rabbitTemplate.send(
                "direct_EX",
                "上海",
                message);//强调自定义properties(优先级,用户id,appid等)
        //basicPublish
        return "success";
    }
}
